package com.polaris.live.ui.message.widget.single_message

import com.blankj.utilcode.util.ColorUtils
import com.polaris.live.R
import com.polaris.live.adapter.MessageAdapter
import com.polaris.live.common.cacha.UserManager
import com.polaris.live.common.constant.CommonConst
import com.polaris.live.databinding.MessageItemCallBinding
import com.polaris.live.im.db.entity.MessageEntity

/**
 * 通话消息
 *
 * @author Created by 半仙 on 2023/10/12/012 13:45
 */
class MessageCallItemHolder(
    adapter: MessageAdapter,
    binding: MessageItemCallBinding
) : AbstractMessageItemHolder<MessageItemCallBinding>(adapter, binding) {

    override fun bind(item: MessageEntity) {
        mBinding.apply {
            bindCommon(
                item,
                layoutTime.messageTextTime,
                layoutLeft,
                layoutRight,
                layoutLeftAvatar.avAvatar,
                layoutRightAvatar.avAvatar,
                layoutLeftAvatar.avFv,
                layoutRightAvatar.avFv,
                null,
                null
            )

            if (item.sender == UserManager.getUser().userId) {
                setRight(item)
            } else {
                setLeft(item)
            }
        }
    }

    private fun setLeft(item: MessageEntity) {
        mBinding.apply {
            messageLeftText.text = item.content

            if (item.payloadBean?.status == CommonConst.CallType.OVER) {
                messageLeftImg.setImageResource(R.drawable.ic_video_reject_ok)
                messageLeftText.setTextColor(ColorUtils.getColor(R.color.f202028))
            } else {
                messageLeftImg.setImageResource(R.drawable.ic_video_reject)
                messageLeftText.setTextColor(ColorUtils.getColor(R.color.color_fe4f3c))
            }
        }
    }

    private fun setRight(item: MessageEntity) {
        mBinding.apply {
            messageRightText.text = item.content

            if (item.payloadBean?.status == CommonConst.CallType.OVER) {
                messageRightImg.setImageResource(R.drawable.me_iv_video)
            } else {
                messageRightImg.setImageResource(R.drawable.me_iv_video_not)
            }
        }
    }
}